{
  Yggdrasil console unit
  Maintainer(s): Timothy O'Neill
}

unit UConsole;

interface

uses
  Forms, SysUtils, Windows,
  UFunctions;

procedure ShowStatus(TargetString : string);
procedure ShowWarning(TargetString : string);
procedure ShowError(TargetString : string);

implementation

const
  //End line
  endl = (chr(10) + chr(13));
  //Console colors
  ConsoleRed = 12;
  ConsoleYellow = 14;
  ConsoleGreen = 10;
  ConsoleWhite = 15;
  ConsoleDefault = 7;

procedure SetConsoleColor(TargetColor : Byte);
begin
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
                          TargetColor OR 0);
end;

procedure ShowLabel(TargetLabel : string; TargetColor : byte);
begin
  Write(endl);
  SetConsoleColor(TargetColor); Write('[');
  SetConsoleColor(ConsoleWhite); Write(TargetLabel);
  SetConsoleColor(TargetColor); Write(']');
  SetConsoleColor(ConsoleDefault); Write(' ');
end;

procedure ShowStatus(TargetString : string);
begin
  ShowLabel('Status', ConsoleGreen);
  Write(TargetString);
end;

procedure ShowWarning(TargetString : string);
begin
  ShowLabel('Warning', ConsoleYellow);
  Write(TargetString);
end;

procedure ShowError(TargetString : string);
begin
  ShowLabel('Error', ConsoleRed);
  Write(TargetString);
end;

initialization
begin
  SetConsoleColor(8); Write('Yggdrasil v' + GetAppVersion() + ' debug console');
end;

finalization
  ShowStatus('Exiting');

end.
